﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;




namespace DotNetNuke.Tests.UI.WatiN.SiteTests
{
    [TestFixture]

    public class RibbonBarTests : STBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {

            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void Verify_RibbonBar_Tabs_Present()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            
            //Assert
            //Assert.IsTrue(ribbonBar.CommonTasksTabLink.Exists);
            //Assert.IsTrue(ribbonBar.CurrentPageTabLink.Exists);
            Assert.IsTrue(ribbonBar.AdminConsoleLink.Exists);
            Assert.IsTrue(ribbonBar.HostConsoleLink.Exists);
            Assert.IsTrue(ribbonBar.ModulesSectionLink.Exists);
            Assert.IsTrue(ribbonBar.PagesSectionLink.Exists);
            Assert.IsTrue(ribbonBar.ToolsSectionLink.Exists);
            

            //Act 
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Assert 
            //Assert.IsTrue(ribbonBar.CommonTasksTabLink.Exists);
            //Assert.IsTrue(ribbonBar.CurrentPageTabLink.Exists);
            Assert.IsTrue(ribbonBar.AdminConsoleLink.Exists);
            Assert.IsFalse(ribbonBar.HostConsoleLink.Exists);
            Assert.IsTrue(ribbonBar.ModulesSectionLink.Exists);
            Assert.IsTrue(ribbonBar.PagesSectionLink.Exists);
            Assert.IsTrue(ribbonBar.ToolsSectionLink.Exists);
        }

        [Test]
        public void Verify_Common_Tasks_Tab_Layout()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.CommonTasksTabLink.Click();
            System.Threading.Thread.Sleep(500);

            //Assert 
            Assert.IsTrue(ribbonBar.EditCurrentPageLink.Exists);
            Assert.IsTrue(ribbonBar.NewPageLink.Exists);
            Assert.IsTrue(ribbonBar.NewPageName.Exists);
            Assert.IsTrue(ribbonBar.TemplateComboBox.Exists);
            Assert.IsTrue(ribbonBar.InsertPageLocationComboBox.Exists);
            Assert.IsTrue(ribbonBar.InsertPageComboBox.Exists);
            Assert.IsTrue(ribbonBar.AddExistingModuleRadioButton.Exists);
            Assert.IsTrue(ribbonBar.ModuleComboBox.Exists);
            Assert.IsTrue(ribbonBar.ModuleTitleField.Exists);
            Assert.IsTrue(ribbonBar.ModuleVisibilityComboBox.Exists);
            Assert.IsTrue(ribbonBar.ModulePaneComboBox.Exists);
            Assert.IsTrue(ribbonBar.InsertComboBox.Exists);
            Assert.IsTrue(ribbonBar.AddModuleButton.Exists);
        }

        [Test]
        public void Verify_Current_Page_Tab_Layout()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.CurrentPageTabLink.Click();
            System.Threading.Thread.Sleep(500);

            //Assert 
            Assert.IsTrue(ribbonBar.EditCurrentPageLink.Exists);
            Assert.IsTrue(ribbonBar.CopyPageLink.Exists);
            Assert.IsTrue(ribbonBar.ImportPageLink.Exists);
            Assert.IsTrue(ribbonBar.ExportPageLink.Exists);
            Assert.IsTrue(ribbonBar.DeletePageLink.Exists);
            Assert.IsTrue(ribbonBar.EditPageNameField.Exists);
            Assert.IsTrue(ribbonBar.MoveLocationComboBox.Exists);
            Assert.IsTrue(ribbonBar.MovePageComboBox.Exists);
            Assert.IsTrue(ribbonBar.PageSkinComboBox.Exists);
            Assert.IsTrue(ribbonBar.UpdatePageLink.Exists);
            Assert.IsTrue(ribbonBar.HelpLink.Exists);
        }

        [Test]
        public void Verify_Admin_Tab_Layout()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            
            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            //ribbonBar.AdminTabLink.Click();
            System.Threading.Thread.Sleep(500);

            //Assert 
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Site Settings").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Pages").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Extensions").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Languages").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Skins").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Security Roles").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("User Accounts").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Vendors").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Site Log").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Newsletters").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("File Manager").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Recycle Bin").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Event Viewer").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Site Wizard").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Google Analytics").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Taxonomy").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Search Engine Site Map").Exists);
        }

        [Test]
        public void Verify_Host_Tab_Layout()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            //ribbonBar.HostTabLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Assert 
            //Host Features
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Host Settings").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Portals").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("File Manager").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Vendors").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("SQL").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Schedule").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Search Admin").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Lists").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("SuperUser Accounts").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Extensions").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Dashboard").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("What's New").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Configuration Manager").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("What's New").Exists);
            //Professional Features
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Manage Web Servers").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Health Monitoring").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Application Integrity").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Search Crawler Admin").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Security Center").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("User Switcher").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Technical Support").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("My Support Tickets").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Activate Your License").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("License Management").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Knowledge Base").Exists);
            Assert.IsTrue(ribbonBar.GetRibbonBarLinkByText("Software and Documentation").Exists);
        }

        [Test]
        public void Verify_Edit_Page_Functionality()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.EditCurrentPageLink.Click();

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            PageSettingsPage settingsPage = new PageSettingsPage(homePage);
            //Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.PopUpTitleSpan.InnerHtml.Contains("Home"));
           // Assert.IsTrue(menu.BreadCrumbSpan.Text.Contains("Home"));
            Assert.IsTrue(settingsPage.PageNameField.Text.Equals("Home"));
        }

        [Test]
        public void Verify_Create_New_Page_Functionality()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            PageSettingsPage settingsPage = new PageSettingsPage(homePage);
            Assert.IsTrue(homePage.PopUpTitleSpan.InnerHtml.Contains("Home"));
            //Assert.IsTrue(menu.BreadCrumbSpan.Text.Contains("Home"));
            Assert.AreNotEqual("Home", settingsPage.PageNameField.Text);
        }

        [Test]
        public void Verify_Add_Page_From_RB_Functionality()
        {
            //Arrange
            string capturePath = CapturePath + @"\RibbonBarTests\AddPageFromRB\";
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            WatiNAssert watiNAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageName.Value = "Test Page";
            ribbonBar.AddPageLink.Click();

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            watiNAssert.AssertIsTrue(menu.MainMenu.InnerHtml.Contains("Test Page"), "TestPageNotInMenu.jpg");
            watiNAssert.AssertIsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Test Page"), "TestPageNotCreated.jpg");
            ieInstance.GoTo(SiteURL + "/Admin/Pages.aspx");
            AdminPagesPage pages = new AdminPagesPage(homePage);
            //Assert.IsTrue(pages.PagesSelectList.Option("Test Page").Index == 1);
            watiNAssert.AssertIsTrue(pages.PageSpans[23].InnerHtml.Contains("Test Page"), "TestPageMissingFromPagesModule.jpg", pages.PageSpans[23].InnerHtml);
        }

        [Test]
        [DependsOn("Verify_Add_Page_From_RB_Functionality")]
        public void Verify_Add_New_Module_Functionality()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            string moduleName = "Test Module";
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Add a page for testing
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageLink.Click();
            PageSettingsPage settingsPage = new PageSettingsPage(homePage);
            settingsPage.AddPageSelectTemplate("Test Page", "None Specified");


            //Act 
            if (VersionType.CompareTo("Community") == 0)
            {
                ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

            }
            else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
            {
                ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

            }

            //Assert 
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Visible By Administrators Only"));
            Assert.IsTrue(homePage.ContentDiv.Div(Find.ById(s => s.EndsWith("HtmlModule_lblContent"))).Exists);
        }

        [Test]
        [DependsOn("Verify_Add_New_Module_Functionality")]
        public void Verify_Add_Existing_Module_To_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            string pageName = "Test Page 1";
            string pageName2 = "Test Page 2";
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Add a page for testing
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);

            //Add a page with a module           
            ribbonBar.NewPageLink.Click();
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");

            System.Threading.Thread.Sleep(2000);
            string moduleContent = "This is module content for testing.";
            string moduleName = "Test Module";

            if (VersionType.CompareTo("Community") == 0)
            {
                ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

            }
            else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
            {
                ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

            }

            //Add another page
            System.Threading.Thread.Sleep(1000);
            ribbonBar.NewPageLink.Click();

            newPage.AddPageSelectTemplate(pageName2, "None Specified");

            //Act
            ieInstance.GoTo(SiteURL + "/testpage2.aspx");
            ribbonBar.AddExistingModuleToPage(pageName, moduleName, "rcbHovered ");
            System.Threading.Thread.Sleep(1000);

            //Assert
            SiteMenu menu = new SiteMenu(homePage);
            Assert.AreEqual(pageName2, menu.BreadCrumbSpan.Text);
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleContent));
        }

        [Test]
        public void Verify_Current_Page_Edit_Functionality()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            //ribbonBar.CurrentPageTabLink.Click();
            ribbonBar.EditCurrentPageLink.Click();

            //Assert
            SiteMenu menu = new SiteMenu(homePage);
            PageSettingsPage settingsPage = new PageSettingsPage(homePage);
            Assert.IsTrue(homePage.PopUpTitleSpan.InnerHtml.Contains("Home"));
            Assert.IsTrue(settingsPage.PageNameField.Text.Equals("Home"));
        }

        [Test]
        public void Verify_Current_Page_Import_Export_Functionality()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            String pageName = "Test Page";
            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Add a page to the site
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.NewPageLink.Click();
              
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");
            System.Threading.Thread.Sleep(1500);

            //Add content to the page 
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            if (VersionType.CompareTo("Community") == 0)
            {
                ribbonBar.AddHTMLModuleToPageWithContent("Export Module", "HTML", "This is content for importing...", 0);
            }
            else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
            {
                ribbonBar.AddHTMLModuleToPageWithContent("Export Module", "HTML Pro", "This is content for importing...", 0);
            }

            //Act 
            //ribbonBar.CurrentPageTabLink.Click();
            System.Threading.Thread.Sleep(1500);
            ribbonBar.ExportPageLink.Click();
            System.Threading.Thread.Sleep(1500);
            //Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.PopUpTitleSpan.Text.Contains(pageName), homePage.PopUpTitleSpan.Text);
            ExportImportPage exportPage = new ExportImportPage(homePage);
            exportPage.ExportTemplateFolderSelectList.Select("Templates");
            exportPage.TemplateNameField.Value = "TestPageNoContent";
            exportPage.TemplateDescriptionField.Value = "This is a template of Test page for testing";
            exportPage.IncludeContentCheckbox.Checked = false;
            exportPage.ExportLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Assert 
            Assert.IsTrue(exportPage.PopUpMessageSpan.InnerHtml.Contains("The Page Template Has Been Created to"));
            Assert.IsTrue(File.Exists(PhysicalPath + @"\Portals\0\Templates\TestPageNoContent.page.template"));

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            //ribbonBar.CurrentPageTabLink.Click();
            ribbonBar.ImportPageLink.Click();
            //Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.PopUpTitleSpan.Text.Contains("Home"), homePage.PopUpTitleSpan.Text);
            exportPage.ImportFolderSelectList.Select("Templates");
            exportPage.TemplateSelectList.Select("TestPageNoContent");
            System.Threading.Thread.Sleep(2000);
            exportPage.CreateNewPageRadioButton.Checked = true;
            exportPage.ViewImportedPageRadioButton.Checked = true;
            exportPage.ImportPageLink.Click();

            //Assert
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.Text.Equals("TestPageNoContent"));
            Assert.IsTrue(menu.MainMenu.InnerHtml.Contains("TestPageNoContent"));
            Assert.IsTrue(menu.MainMenu.InnerHtml.Contains(pageName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Export Module"));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains("This is content for importing..."));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains("Visible By Administrators Only"));

            //Clean up the file
            File.Delete(PhysicalPath + @"\Portals\0\Templates\TestPageNoContent.page.template");
        }

        [Test]
        public void Verify_Current_Page_Delete_Functionality()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            String pageName = "Test Page";
            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);
            RibbonBar ribbonBar = new RibbonBar(homePage);

            ieInstance.GoTo(SiteURL + "/GettingStarted.aspx");
            //ribbonBar.CurrentPageTabLink.Click();
            Assert.IsTrue(ribbonBar.DeletePageLink.Title.Contains("Cannot delete this page"));

            //A page must first be added
            //ribbonBar.CommonTasksTabLink.Click();
            ribbonBar.NewPageLink.Click();
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPage(pageName);
            //ribbonBar.CurrentPageTabLink.Click();

            //Act
            ribbonBar.DeletePageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            ribbonBar.PopUpCancelation.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.Text.Contains(pageName));

            ribbonBar.DeletePageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            ribbonBar.PopUpConfirmation.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Assert
            Assert.IsFalse(menu.MainMenu.InnerHtml.Contains(pageName));
            ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
            RecycleBinPage recycleBin = new RecycleBinPage(homePage);
            Assert.IsTrue(recycleBin.PagesRecycleBin.InnerHtml.Contains(pageName));
        }

        [Test]
        public void Verify_Current_Page_Update_Functionality()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            String pageName = "Test Page";
            String pageName2 = "Other Test Page";

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Add A skin for testing 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);

            RibbonBar ribbonBar = new RibbonBar(homePage);
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Two pages must first be added
            //ribbonBar.CommonTasksTabLink.Click();
            ribbonBar.NewPageLink.Click();
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPage(pageName);

            ribbonBar.NewPageLink.Click();
            newPage.AddPage(pageName2);

            //Act
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            //ribbonBar.CurrentPageTabLink.Click();
            Element item = null;
            String newPageName = "New Page Name";
            ribbonBar.EditPageNameField.Value = newPageName;
            ribbonBar.EditPageLocationSelectList.Select("Child of");
            ribbonBar.EditPageLocationPageSelectList.Select(pageName2);
            //item = ribbonBar.GetItemFromTelerikComboBox("Move Location", ribbonBar.MoveLocationSelectDiv, "rcbItem ", "Child of");
            //item.FireEvent("onmouseover");
            //item.Click();
            //item = ribbonBar.GetItemFromTelerikComboBox("Move Page", ribbonBar.MovePageSelectDiv, "rcbItem ", pageName2);
            //item.FireEvent("onmouseover");
            //item.Click();
            item = ribbonBar.GetItemFromTelerikComboBox("Skin", ribbonBar.SkinSelectDiv, "rcbItem ", SkinUsed);
            item.FireEvent("onmouseover");
            item.Click();
            ribbonBar.UpdatePageLink.ClickNoWait();

            //Assert
            System.Threading.Thread.Sleep(2000);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains(pageName2));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains(newPageName));
            Assert.IsTrue(menu.MainMenu.InnerHtml.Contains(newPageName));

            //Check the skin was updated correctly
            ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            Regex stylesheetRegex = new Regex(@".*_Skins_" + SkinName + "_", RegexOptions.IgnoreCase);
            Element stylesheet = header.Elements.Filter(Find.ById(stylesheetRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            ieInstance.GoTo(SiteURL + "/Admin/Pages.aspx");
            //AdminPagesPage pages = new AdminPagesPage(homePage);
            //Assert.IsTrue(pages.PagesSelectList.Option("..." + newPageName).Exists);

            //Check that other pages still have the default skin
            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            String defaultSkinString = "Skins_DarkKnight_";
            //if (VersionType.CompareTo("Community") == 0)
            //{
            //    minimalExtropyString = "Skins_MinimalExtropy_";
            //}
            //else
            //{
            //    minimalExtropyString = "Skins_MinimalExtropyPro_";
            //}

            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(defaultSkinString)))[0];
            Assert.IsTrue(stylesheet.Exists);
        }

        [Test]
        public void Verify_Current_Page_Copy_Permissions_to_Children()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            String pageName = "Test Page";
            String childName = "Child Page";

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            RibbonBar ribbonBar = new RibbonBar(homePage);
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Two pages must first be added
            ribbonBar.CommonTasksTabLink.ClickNoWait();
            ribbonBar.NewPageLink.ClickNoWait();
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");
            System.Threading.Thread.Sleep(2000);
            ribbonBar.NewPageLink.ClickNoWait();
            newPage.AddChildPage(childName, pageName);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/TestPage.aspx");
            ribbonBar.CurrentPageTabLink.Click();
            ribbonBar.CopyPermissionsToChildrenLink.Click();
            ribbonBar.PopUpCancelation.Click();
            ieInstance.GoTo(SiteURL + "/TestPage/ChildPage.aspx");            
            ribbonBar.EditCurrentPageLink.Click();
            PageSettingsPage settingsPage = new PageSettingsPage(homePage);
            System.Threading.Thread.Sleep(1000);
            Assert.IsFalse(settingsPage.GetViewPermissionsForRole("All Users"));

            ieInstance.GoTo(SiteURL + "/TestPage.aspx");
            ribbonBar.CopyPermissionsToChildrenLink.Click();
            ribbonBar.PopUpConfirmation.Click();
            ieInstance.GoTo(SiteURL + "/TestPage/ChildPage.aspx");
            ribbonBar.EditCurrentPageLink.Click();
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(settingsPage.GetViewPermissionsForRole("All Users"));
            Assert.IsFalse(settingsPage.GetEditPermissionsForRole("All Users"));
            Assert.IsFalse(settingsPage.GetViewPermissionsForRole("Registered Users"));
            Assert.IsFalse(settingsPage.GetViewPermissionsForRole("Subscribers"));
            Assert.IsFalse(settingsPage.GetViewPermissionsForRole("Unauthenticated Users"));
        }

        [Test]
        public void Verify_Current_Page_Copy_Design_to_Children()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            String pageName = "Test Page";
            String childName = "Child Page";

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Add a skin to the site
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
            System.Threading.Thread.Sleep(1500);
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);

            RibbonBar ribbonBar = new RibbonBar(homePage);
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Two pages must first be added
            //ribbonBar.CommonTasksTabLink.Click();
            ribbonBar.NewPageLink.Click();
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPage(pageName);
            System.Threading.Thread.Sleep(2000);
            //Select the skin for the page 
            ribbonBar.EditCurrentPageLink.Click();
            newPage.AdvancedSettingsTabLink.Click();
            newPage.PageSkinSelect.Select(SkinUsed);
            newPage.PageContainerSelect.Select(ContainerUsed);
            newPage.UpdatePageLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);

            ribbonBar.NewPageLink.Click();
            newPage.AddChildPage(childName, pageName);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/TestPage.aspx");
            //ribbonBar.CurrentPageTabLink.Click();
            ribbonBar.CopyDesignToChildrenLink.Click();
            ribbonBar.PopUpCancelation.Click();
            ieInstance.GoTo(SiteURL + "/TestPage/ChildPage.aspx");

            
            ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
        
            Regex skinRegex = new Regex(@".*_Skins_MinimalExtropy.*_", RegexOptions.IgnoreCase);
            Element stylesheet = header.Elements.Filter(Find.ById(skinRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

            Regex containerRegex = new Regex(@".*_Containers_MinimalExtropy.*_", RegexOptions.IgnoreCase);
            stylesheet = header.Elements.Filter(Find.ById(containerRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

            ieInstance.GoTo(SiteURL + "/TestPage.aspx"); 
            ribbonBar.CopyDesignToChildrenLink.Click();
            ribbonBar.PopUpConfirmation.Click();
            System.Threading.Thread.Sleep(1500);
            ieInstance.GoTo(SiteURL + "/TestPage/ChildPage.aspx");
            System.Threading.Thread.Sleep(1500);

            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            skinRegex = new Regex(@".*_Skins_" + SkinName + "_", RegexOptions.IgnoreCase);
            stylesheet = header.Elements.Filter(Find.ById(skinRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

            containerRegex = new Regex(@".*_Containers_" + SkinName + "_", RegexOptions.IgnoreCase);
            stylesheet = header.Elements.Filter(Find.ById(containerRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
        }

        [Test]
        public void Verify_Help_On_Current_Page_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.CurrentPageTabLink.Click();
            ribbonBar.HelpLink.Click();

            //Assert 
            System.Threading.Thread.Sleep(5000);
            IE popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.dotnetnuke.com")));
            Assert.IsTrue(popUpWindow.Title.Contains("DotNetNuke > Resources > Support > Online Manual"));
            popUpWindow.Close();

        }

        [Test]
        public void Verify_Site_Settings_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.SiteSettingsLink, "Site Settings", "Site Settings", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Console_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.AdminConsoleLink.Click();
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Basic Features"));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Admin"));
        }

        [Test]
        public void Verify_Users_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
           
            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.UsersLink, "User Accounts", "User Accounts", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_User_Roles_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Roles"), "Security Roles", "Security Roles", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Add_User_Role_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Add Role"), "Edit Security Roles", "Security Roles", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Add_User_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Add User"), "Edit User Accounts", "User Accounts", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Pages_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Pages"), "Pages", "Pages", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_New_Page_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.AddNewPageLinkAdminTab, "Page Settings", "Home", ribbonBar, homePage, 1);
            PageSettingsPage settingsPage = new PageSettingsPage(homePage);
            Assert.AreNotEqual("Home", settingsPage.PageNameField.Text);
        }

        [Test]
        public void Verify_File_Manager_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            
            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("File Manager"), "File Manager", "File Manager", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Upload_File_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Upload File"), "File Upload", "File Manager", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Newsletters_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("News Letters"), "Newsletters", "Newsletters", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Extensions_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Extensions"), "Extensions", "Extensions", ribbonBar, homePage, 1);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Admin"));
        }

        [Test]
        public void Verify_Skins_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Skins"), "Skin Editor", "Skins", ribbonBar, homePage, 2);
        }

        [Test]
        public void Verify_Languages_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Languages"), "Language Management", "Languages", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Event_Log_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Event Log"), "Log Viewer", "Event Viewer", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Site_Log_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Site Log"), "Site Log", "Site Log", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Recycle_Bin_On_Admin_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnAdminTab(ribbonBar.GetRibbonBarLinkByText("Recycle Bin"), "Recycle Bin", "Recycle Bin", ribbonBar, homePage, 1);
        }

        [Test]
        public void Verify_Host_Settings_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.GetRibbonBarLinkByText("Host Settings"), "Host Settings", "Host Settings", ribbonBar, homePage);
        }

        [Test]
        public void Verify_Console_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.HostConsoleLink.Click();
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Basic Features"));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Host"));
        }

        [Test]
        public void Verify_Super_User_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.GetRibbonBarLinkByText("Super Users"), "Superuser Accounts", "SuperUser Accounts", ribbonBar, homePage);
        }

        [Test]
        public void Verify_File_Manager_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.HostFileManagerLink, "File Manager", "File Manager", ribbonBar, homePage);
        }

        [Test]
        public void Verify_Extensions_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.HostExtensionsLink, "Extensions", "Extensions", ribbonBar, homePage);
        }

        [Test]
        public void Verify_Sites_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.GetRibbonBarLinkByText("Sites"), "Portals", "Portals", ribbonBar, homePage);
        }

        [Test]
        public void Verify_Dashboard_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.GetRibbonBarLinkByText("Dashboard"), "Dashboard", "Dashboard", ribbonBar, homePage);
        }

        [Test]
        public void Verify_Whats_New_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.GetRibbonBarLinkByText("What's New"), "What's New", "What's New", ribbonBar, homePage);
        }

        [Test]
        public void Verify_MarketPlace_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.GetRibbonBarLinkByText("Marketplace"), "Marketplace", "Marketplace", ribbonBar, homePage);
        }

        [Test]
        public void Verify_SQL_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.GetRibbonBarLinkByText("SQL"), "SQL", "SQL", ribbonBar, homePage);
        }

        [Test]
        public void Verify_Scheduler_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Act & Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            VerifyLinkOnHostTab(ribbonBar.GetRibbonBarLinkByText("Scheduler"), "Schedule", "Schedule", ribbonBar, homePage);
        }

        [Test]
        public void Verify_Switch_Sites_On_Host_Tab()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            //Add A portal
            string portalName = "My Test Portal";
            string portalAlias = portalName.Replace(" ", "");
            ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
            HostPortalPage portalPage = new HostPortalPage(homePage);
            portalPage.AddChildPortalDontClickMsgLink(ApplicationName, "My Test Portal", "MyTestPortal");
            System.Threading.Thread.Sleep(2000);
            
            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.HostTabLink.Click();
            Element item = ribbonBar.GetItemFromTelerikComboBox("Site", ribbonBar.SiteSelectDiv, "rcbItem ", portalName);
            item.FireEvent("onmouseover");
            item.Click();
            ribbonBar.SwitchSiteButton.Click();

            //Assert 
            System.Threading.Thread.Sleep(2000);
            Assert.IsTrue(ieInstance.Url.ToLower().Contains("localhost/" + ApplicationName.ToLower() + "/" + portalAlias.ToLower()), "URL is: " + ieInstance.Url);
            //Delete the portal folders
            Directory.Delete(PhysicalPath + @"\mytestportal", true);
            Directory.Delete(PhysicalPath + @"\Portals\1", true);
        }

        [Test]
        public void Verify_Copy_Modules_Checkbox_Exists()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");

            SelectRibbonBarAsControlPanelStyle(TestUsers.Host.Email, homePage);

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            RibbonBar ribbonBar = new RibbonBar(homePage);
            ribbonBar.AddExistingModuleRadioButton.Checked = true;
            System.Threading.Thread.Sleep(1500);

            //Assert 
            Assert.IsTrue(ribbonBar.CopyExistingModuleCheckBox.Exists);
        }


        #endregion

        private void SelectRibbonBarAsControlPanelStyle(string hostEmail, WatiNBase homePage)
        {
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.HostEmailTextField.Value = hostEmail;
            hostSettings.OtherSettingsTab.ClickNoWait();
            hostSettings.ControlPanelStyleSelectList.Select("RIBBONBAR");
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
        }

        private void VerifyLinkOnAdminTab(Link link, string pageTitle, string breadcrumb, RibbonBar ribbonBar, WatiNBase homePage, int moduleCount)
        {
            ribbonBar.AdminTabLink.Click();
            System.Threading.Thread.Sleep(500);
            link.Click();

            //Assert 
            System.Threading.Thread.Sleep(1000);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == moduleCount);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains(pageTitle));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains(breadcrumb));
        }

        private void VerifyLinkOnHostTab(Link link, string pageTitle, string breadcrumb, RibbonBar ribbonBar, WatiNBase homePage)
        {
            ribbonBar.HostTabLink.Click();
            System.Threading.Thread.Sleep(500);
            link.Click();

            //Assert 
            System.Threading.Thread.Sleep(1000);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains(pageTitle));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains(breadcrumb));
            Assert.IsTrue(menu.BreadCrumbSpan.InnerHtml.Contains("Host"));
        }


    }

}

